<?php
	include("../include/init.php");//将配置文件全部加载进来
	include("../include/check_login.php");//登录

	$order = new sql_class("order");



	
	//连表查询
	/*$select = "AS article LEFT JOIN pre_article_cate AS cate ON article.artcate_id = cate.artcate_id";
	$artcate_list = $insert->select("1","",$select)->getAll();
	var_dump($artcate_list);exit;*/



	//单条删除
	$order_id = isset($_GET['order_id']) ? $_GET['order_id'] : 0;
	if($order_id){
		$order_del = $order->delete("order_id = $order_id");
		if($order_del){
			show_msg("删除订单成功","order_list.php");
			exit;	
		}else{
			show_msg("删除订单成功","order_list.php");
			exit;
		}
	}

	//多条删除
	$order_id = isset($_GET['id']) ? implode(",",$_GET['id']) : 0;
	if($order_id){
		$where = "order_id IN($order_id)";
		$affect_id =$order->delete($where);
		if($affect_id){
			show_msg("批量删除订单成功","order_list.php");
			exit;
		}else{
			show_msg("批量删除订单失败","order_list.php");
			exit;
		}

	}

	$start_time = isset($_GET['start_time']) ? $_GET['start_time'] : 0;
	$end_time = isset($_GET['end_time']) ? $_GET['end_time'] : 0;
	$keywords = isset($_GET['keywords']) ? trim($_GET['keywords']) : 0;

	$start_time = strtotime($start_time);
	$end_time = strtotime($end_time);
	$where = "";
	if($start_time && !$end_time){
		$where = "order_time > $start_time";
	}else if(!$start_time && $end_time){
		$where = "order_time < $end_time";
	}else if($start_time && $end_time){
		$where = "order_time between $start_time and $end_time";
	}else if(!empty($keywords)){
		$where = "order_sn = '$keywords'";
	}else{
		$where = 1;
	}
	


	$current = isset($_GET['page']) ? $_GET['page'] : 1;//获取页数
	$limit = 6;
	$size = 4;
	$count = $order->select($where,"COUNT(*) AS c")->getOne();
	
	$page_str = page($current,$count['c'],$limit,$size);
	$start = ($current - 1)*$limit;
	$order_list = $order->select($where)->orderBy(["order_id","DESC"])->limit([$start,$limit])->getAll();
	


	$smarty->assign("start_time",$start_time);
	$smarty->assign("end_time",$end_time);
	$smarty->assign("order_list",$order_list);
	$smarty->assign("page_str",$page_str);
	$smarty->display("admin/order_list.html");



?>